﻿using SuddenDeath.Domain.Services.FileManager.elFinder.Responses;
using SuddenDeath.Domain.Services.FileManager.elFinder.Utils;

namespace SuddenDeath.Domain.Services.FileManager.elFinder.Commands
{
    public class MkDir : ICommand
    {
        public string Current { get; set; }

        public string Name { get; set; }

        public MkDir(string current, string name)
        {
            Current = current;

            Name = name;
        }

        #region ICommand Members       

        public Response Execute()
        {
            var path = DirectoryUtils.GetRelativePathByHash(Current, Configuration.Configuration.RootPath);

            System.IO.Directory.CreateDirectory(path + @"\" + Name);

            var folder = new Folder(path);

            var response = new ActionCompletedResponse
                               {
                                   cwd = folder.Cwd,
                                   cdc = folder.Contents,
                                   tree = folder.Tree,
                                   Select = new[] {(path + @"\" + Name).Hash()}
                               };

            return response;
        }

        #endregion
    }
}
